<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Script Compiler (Ahk2Exe) Directives</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="http://ahkscript.org/docs/css/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Script Compiler (Ahk2Exe) Directives <span class="ver">[v1.1.??+]</span></h1>

<h2>Note: This file is depreciated! The updated documentation is now in the standard AutoHotkey.chm help file.</h2>

<p>The script compiler accepts certain directives that allow further
customisation the compiled script (.exe).<br>All compiler directives are introduced by the string <code>@Ahk2Exe-</code>, preceded by the comment flag.</p>

<h2 id="IgnoreKeep">Directives that control the script behaviour</h2>
<p>It is possible to remove code sections from the compiled script by wrapping
them in directives:</p>
<pre class="NoIndent">MsgBox This message appears in both the compiled and uncompiled script
<em>;@Ahk2Exe-IgnoreBegin</em>
MsgBox This message does NOT appear in the compiled script
<em>;@Ahk2Exe-IgnoreEnd</em>
MsgBox This message appears in both the compiled and uncompiled script
</pre>
<p>The reverse is also possible, i.e. marking a code section to only be executed in
the compiled script:</p>
<pre class="NoIndent"><em>/*@Ahk2Exe-Keep
MsgBox This message appears only in the compiled script
*/</em>
MsgBox This message appears in both the compiled and uncompiled script
</pre>
<p>This has advantage over <a href="http://ahkscript.org/docs/Variables.htm#IsCompiled">A_IsCompiled</a> because
the code is completely removed from the compiled script during preprocessing, thus making
the compiled script smaller. The reverse is also true: it will not be necessary to check
for A_IsCompiled because the code is inside a comment block in the uncompiled script.</p>

<h2 id="Directives">Directives that control executable metadata</h2>
<p>In the parameters of these directives, the following escape sequences are supported:
<code>``</code>, <code>`,</code>, <code>`n</code>, <code>`r</code> and <code>`t</code>.
Commas <em>always</em> need to be escaped, regardless of the parameter position.
"Integer" refers to unsigned 16-bit integers (0..0xFFFF).</p>

<p>If required, directive parameters can reference the following list of standard built-in variables by enclosing the variable name with <code>%</code> signs:-</p> <p><b>Group 1: </b><code>A_AhkPath</code>, <code>A_AppData</code>, <code>A_AppDataCommon</code>, <code>A_ComputerName</code>, <code>A_ComSpec</code>, <code>A_Desktop</code>, <code>A_DesktopCommon</code>, <code>A_MyDocuments</code>, <code>A_ProgramFiles</code>, <code>A_Programs</code>, <code>A_ProgramsCommon</code>, <code>A_ScriptDir</code>, <code>A_ScriptFullPath</code>, <code>A_ScriptName</code>, <code>A_Space</code>, <code>A_StartMenu</code>, <code>A_StartMenuCommon</code>, <code>A_Startup</code>, <code>A_StartupCommon</code>, <code>A_Tab</code>, <code>A_Temp</code>, <code>A_UserName</code>, <code>A_WinDir</code>.</p> 

<p><b>Group 2: </b><code>A_AhkVersion</code>, <code>A_IsCompiled</code>, <code>A_IsUnicode</code>, <code>A_PtrSize</code>.</p> 

<p>In addition to these variable names, the special variable <code>A_WorkFileName</code> holds the temporary name of the processed .exe file. This can be used to pass the file name as a parameter to any <code>PostExec</code> directives which need to access the generated .exe.</p>

<p>Also, the special variable <code>A_PriorLine</code> contains the source line immediately preceding the current compiler directive. Intervening lines of blanks and comments only are ignored, as are any intervening compiler directive lines. This variable can be used to 'pluck' constant information from the script source, and use it in later compiler directives. An example would be accessing the version number of the script, which may be changed often. Accessing the version number in this way means that it needs to be changed only once in the source code, and the change will get copied through to the necessary directive. (See the example below for more information.)</p>

<p>As well, special user variables can be created with the format  <code>U_<i>Name</i></code> using the <code>Let</code> directive, described below.</p>

<p>In addition to being available for directive parameters, all variables can be accessed from any RT_MENU, RT_DIALOG, RT_STRING, RT_ACCELERATORS, RT_HTML, and RT_MANIFEST file supplied to the <code>AddResource</code> directive, below.</p>

<p>If needed, the value returned from the above variables can be manipulated by including at the end of the built-in variable name before the ending <code>%</code>, up to 2 parameters (called p2 and p3) all separated by tilde <code>~</code>. The p2 and p3 parameters will be used as literals in the 2nd and 3rd parameters of a <a href="https://www.autohotkey.com/docs/commands/RegExReplace.htm">RegExReplace</a> function to manipulate the value returned. (See <a href="https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm">RegEx Quick Reference</a>.) Note that p3 is optional.</p>

<p>To include a tilde as data in p2 or p3, preceded it with a back-tick,  i.e. <code>`~</code>.
<br>To include a back-tick character as data in p2 or p3, double it, i.e. <code>``</code>.</p>

Regex examples:<ul>
<li><code>%A_ScriptName~\.[^\.]+$~.exe%</code> replaces the extension plus preceding full-stop, with <code>.exe</code> in the actual script name.<br>

(<code>\.[^\.]+$~.exe</code> means scan for a <code>.</code> followed by 1 or more non-<code>.</code> characters followed by end-of-string, and replace them with <code>.exe</code>)</li><br>

<li>Assume there is a source line followed by two compiler directives as follows:<br>
<code>CodeVersion := "1.2.3.4", company := "My Company"</code><br>
<code>;@Ahk2Exe-Let version = %A_PriorLine~U)^(.+"){1}(.+)".*$~$2%</code><br>
<code>;@Ahk2Exe-Let company = %A_PriorLine~U)^(.+"){3}(.+)".*$~$2%</code><br>
These directives copy the version number <code>1.2.3.4</code> into the special variable <code>U_version</code>, and the company name <code>My Company</code> into the special variable <code>U_company</code> for use in other directives later.<br>
(The <code>{1}</code> in the first regex was changed to <code>{3}</code> in the second regex to select after the third <code>"</code> to extract the company name.)</li></ul><br>

<div class="methodShort" id="AddResource"><h2>AddResource</h2>
<p>Adds a resource to the compiled executable. (Also see <code>UseResourceLang</code> below)</p>
<pre class="Syntax">;@Ahk2Exe-AddResource FileName [, ResourceName]</pre>
<table class="info">
<tr><td width="15%">FileName</td><td width="85%">The filename of the resource to add. The type of the resource
(as an integer or string) can be explicitly specified prepending an asterisk to it: <code>*type Filename</code>.
If omitted, Ahk2Exe automatically detects the type according to the file extension.</td></tr>
<tr><td width="15%">ResourceName</td><td width="85%"><i>(Optional)</i> The name that the resource will have
(can be a string or an integer). If omitted, it defaults to the name (with no path) of the file, in uppercase.</td></tr>
</table>
<p>Here is a list of common standard resource types and the extensions that trigger them by default.</p>
<ul>
<li>2 (RT_BITMAP): <code>.bmp</code>, <code>.dib</code></li>
<li>4 (RT_MENU)</li>
<li>5 (RT_DIALOG)</li>
<li>6 (RT_STRING)</li>
<li>9 (RT_ACCELERATORS)</li>
<li>10 (RT_RCDATA): Every single other extension.</li>
<li>11 (RT_MESSAGETABLE)</li>
<li>12 (RT_GROUP_CURSOR): <code>.cur</code> (not yet supported)</li>
<li>14 (RT_GROUP_ICON): <code>.ico</code></li>
<li>23 (RT_HTML): <code>.htm</code>, <code>.html</code>, <code>.mht</code></li>
<li>24 (RT_MANIFEST): <code>.manifest</code>. If the name for the resource is not specified, it defaults to <code>1</code></li>
</ul>
</div>

<div class="methodShort" id="Bin"><h2>Bin</h2>
<p>Specifies the Binary version of AutoHotkey to be included in the generated .exe. (Also see the <code>ExeName</code> directive.)<br>This directive can be specified many times if necessary, but only in the top level script file (i.e. not in an #Include file).<br>(If an actual comment is appended to this directive, it must use the <code>&nbsp;;</code> flag.
<br>To truly comment out this directive, insert a space after the first comment flag.)</td></p>
<pre class="Syntax">;@Ahk2Exe-Bin [Path\]Name [, [Exe_path\][Name] , Codepage]</pre>
<table class="info">
<tr><td width="15%">[Path\]Name</td><td width="85%">The *.bin file to use. If no extension is supplied, <code>.bin</code> is assumed.
<br>A DOS mask may be specified for the <code>name</code> part,
<br>e.g. <code>ANSI*</code>, <code>Unicode 32*</code>, <code>Unicode 64*</code>, or <code>*bit</code> for all three.
<br>If no path is specified, the standard *.bin files in the compiler folder are searched.
<br>The compiler will be run for each *.bin file that matches.
<br>Any use of built-in variable replacements must only be from group 1 above.
</tr>
<tr><td width="15%">Exe_path\<br>Name</td><td width="85%"><i>(Optional)</i> The  file name to be given to the .exe.<br>Any extension supplied will be replaced by <code>.exe</code>.<br>If no path is specified, the .exe will be created in the script folder.<br>If no name is specified, the .exe will have the default name.<br>(This parameter can be overridden by the <code>ExeName</code> directive.)</td></tr>
<tr><td width="15%">Codepage</td><td width="85%"><i>(Optional)</i> Overrides the default <a href="http://msdn.microsoft.com/en-us/library/dd317756.aspx">codepage</a>
 used to process script files.<br>(Scripts should begin with a Unicode byte-order-mark (BOM), rendering the use of this parameter unnecessary.)</td></tr>
</table>
</div>

<div class="methodShort" id="ConsoleApp"><h2>ConsoleApp</h2>
<p>Changes the executable subsystem to Console mode.</p>
<pre class="Syntax">;@Ahk2Exe-ConsoleApp</pre>
</div>

<div class="methodShort" id="Cont"><h2>Cont</h2>
<p>Specifies a continuation line for the preceding directive. This allows a long-lined directive to be formatted so that it is easy to read in the source code.</p>
<pre class="Syntax">;@Ahk2Exe-Cont Text</pre>
<table class="info">
<tr><td width="15%">Text</td><td width="85%">The text to be appended to the previous directive line, before that line is processed. <br>The text starts after the single space following the <code>Cont</code> key-word.</td></tr>
</table>
</div>
<div class="methodShort" id="Debug"><h2>Debug</h2>
<p>Shows a msgbox with the supplied text, for debugging purposes.</p>
<pre class="Syntax">;@Ahk2Exe-Debug Text</pre>
<table class="info">
<tr><td width="15%">Text</td><td width="85%">The text to be shown.
Include any special variables between <code>%</code> signs to see the (manipulated) contents.</td></tr>
</table>
</div>

<div class="methodShort" id="ExeName"><h2>ExeName</h2>
<p>Specifies the location and name given to the generated .exe file. (Also see the <code>Bin</code> directive.)</p>
<pre class="Syntax">;@Ahk2Exe-ExeName [Path\][Name]</pre>
<table class="info">
<tr><td width="15%">Path\<br>Name</td><td width="85%">The .exe file name. Any extension supplied will be replaced by <code>.exe</code>.<br>If no path is specified, the .exe will be created in the script folder.<br>If no name is specified, the .exe will have the default name.
<br>An example:<br><code>;@Ahk2Exe-Obey bits, = %A_PtrSize% * 8</code><br><code>
;@Ahk2Exe-Obey type, = "%A_IsUnicode%" ? "Unicode" : "ANSI"</code><br><code>
;@Ahk2Exe-ExeName %A_ScriptName~\.[^\.]+$%_%U_type%_%U_bits%</code>
</td></tr>
</table>
</div>

<div class="methodShort" id="Let"><h2>Let</h2>
<p>Creates (or modifies) one or more user variables which can be accessed by <code>%U_<i>Name</i>%</code>, similar to the built-in variables (see above).</p>
<pre class="Syntax">;@Ahk2Exe-Let Name = Value [, Name = Value [, ...]]</pre>
<table class="info">
<tr><td width="15%">Name</td><td width="85%">The name of the variable (with or without the leading <code>U_</code>).</td></tr>
<tr><td width="15%">Value</td><td width="85%">The value to be used.</td></tr>
</table>
</div>

<div class="methodShort" id="Obey"><h2>Obey</h2>
<p>Obeys isolated AutoHotkey commands or expressions, with result in <code>U_<i>Name</i></code>.</p>
<pre class="Syntax">;@Ahk2Exe-Obey Name, CmdOrExp [, Extra]</pre>
<table class="info">
<tr><td width="15%">Name</td><td width="85%">The name of the variable (with or without the leading <code>U_</code>) to receive the result.</td></tr>
<tr><td width="15%">CmdOrExp</td><td width="85%">The command or expression to obey.<br><b>Expression</b> format must start with <code>=</code>,
<br>e.g. <code>Obey type, = "%A_IsUnicode%" ? "Unicode" : "ANSI"</code>. <br><b>Command</b> format must use <code>Name</code> as the output variable (often the first parameter),<br>e.g. <code>Obey date, FormatTime date`, R D2 T2</code><br>(Expressions can be written in command format,
<br>e.g. <code>Obey bits, bits := %A_PtrSize% * 8</code>.
<br>If needed, separate multiple commands, expressions with <code>`n</code>.)</td></tr>
<tr><td width="15%">Extra</td><td width="85%"><i>(Optional)</i> A number (1-9) specifying the number of extra results to be returned.
<br>e.g. if extra = 2, results will be returned in <code>U_<i>name</i></code>, <code>U_<i>name</i>1</code>, and <code>U_<i>name</i>2</code>.
<br>The values in the <code><i>name</i></code>s must first be set by the expression or command.</td></tr></table>
</div>

<div class="methodShort" id="PostExec"><h2>PostExec</h2>
<p>Specifies a program to be executed after a successful compilation, before any compression is applied to the .exe.</p>
<pre class="Syntax">;@Ahk2Exe-PostExec Program [parameters]</pre>
<table class="info">
<tr><td width="15%">Program</td><td width="85%">The program [plus parameters] to execute.<br>To allow access to the processed .exe file,
specify the built-in variable <code>%A_WorkFileName%</code> as a parameter, between double-quotes. (See above.)<br>If the program changes the .exe, the altered .exe must be moved back to the input file specified by <code>%A_WorkFileName%</code>, by the program.<br>(Note that the .exe will contain binary data.)</td></tr>
</table>
</div>

<div class="methodShort" id="SetMainIcon"><h2>SetMainIcon</h2>
<p>Overrides the custom EXE icon used for compilation.</p>
<pre class="Syntax">;@Ahk2Exe-SetMainIcon [IcoFile]</pre>
<table class="info">
<tr><td width="15%">IcoFile</td><td width="85%"><i>(Optional)</i> The icon file to use. If omitted, the default AutoHotkey icon is used.</td></tr>
</table>
</div>

<div class="methodShort" id="SetProp"><h2>Set<em>Prop</em></h2>
<p>Changes a property in the compiled executable's version information. Note that all properties are processed in alphabetical order, regardless of the order they are specified.</p>
<pre class="Syntax">;@Ahk2Exe-Set<i>Prop</i> Value</pre>
<table class="info">
<tr><td width="15%">Prop</td><td width="85%">The name of the property to change. Must be one of those listed below.</td></tr>
<tr><td width="15%">Value</td><td width="85%">The value to set the property to.</td></tr>
</table>
<p><b>The following properties are supported by this directive:</b></p>
<table class="info">
<tr><td width="15%">CompanyName</td><td width="85%">Changes the company name.</td></tr>
<tr><td width="15%">Copyright</td><td width="85%">Changes the legal copyright information.</td></tr>
<tr><td width="15%">Description</td><td width="85%">Changes the file description.</td></tr>
<tr><td width="15%">FileVersion</td><td width="85%">Changes the file version, in both text and raw binary format.</td></tr>
<tr><td width="15%">InternalName</td><td width="85%">Changes the internal name.</td></tr>
<tr><td width="15%">Language</td><td width="85%">Changes the  <a href="http://ahkscript.org/docs/misc/Languages.htm">language code</a>. <br>Please note that hexadecimal numbers must have an <code>0x</code> prefix.</td></tr>
<tr><td width="15%">LegalTrademarks</td><td width="85%">Changes the legal trademarks information.</td></tr>
<tr><td width="15%">Name</td><td width="85%">Changes the product name and the internal name.</td></tr>
<tr><td width="15%">OrigFilename</td><td width="85%">Changes the original filename information.</td></tr>
<tr><td width="15%">ProductName</td><td width="85%">Changes the product name.</td></tr>
<tr><td width="15%">ProductVersion</td><td width="85%">Changes the product version, in both text and raw binary format.</td></tr>
<tr><td width="15%">Version</td><td width="85%">Changes the file version and the product version, in both text and raw binary format. Ahk2Exe fills the binary version fields with the period-delimited numbers (up to four)
that may appear at the beginning of the version text. Unfilled fields are set to zero. For example,
<code>1.3-alpha</code> would produce a binary version number of <code>1.3.0.0</code>. If this property is
not modified, it defaults to the AutoHotkey version used to compile the script.</td></tr>
</table>
</div>

<div class="methodShort" id="Set"><h2>Set</h2>
<p>Changes other miscellaneous properties in the compiled executable's version information not covered by the <code>Set<i>Prop</i></code> directive. Note that all properties are processed in alphabetical order, regardless of the order they are specified. This directive is for specialised use only.</p>
<pre class="Syntax">;@Ahk2Exe-Set Prop, Value</pre>
<table class="info">
<tr><td width="15%">Prop</td><td width="85%">The name of the property to change.</td></tr>
<tr><td width="15%">Value</td><td width="85%">The value to set the property to.</td></tr>
</table>
</div>

<div class="methodShort" id="UpdateManifest"><h2>UpdateManifest</h2>
<p>Changes details in the .exe's manifest. This directive is for specialised use only.</p>
<pre class="Syntax">;@Ahk2Exe-UpdateManifest RequireAdmin [, Name, Version]</pre><table class="info">
<tr><td width="15%">RequireAdmin</td><td width="85%">Set to 1 to change the executable to require administrative privileges when run. Set to 0 to leave unchanged.</td></tr><tr><td width="15%">Name</td><td width="85%"><i>(Optional)</i> The name to be set in the manifest. (Not normally used.)</td></tr><tr><td width="15%">Version</td><td width="85%"><i>(Optional)</i> The version to be set in the manifest. (Not normally used.)</td></tr>
</table>
</div>

<div class="methodShort" id="UseResourceLang"><h2>UseResourceLang</h2>
<p>Changes the resource language used by <code>AddResource</code>.</p>
<pre class="Syntax">;@Ahk2Exe-UseResourceLang LangCode</pre>
<table class="info">
<tr><td width="15%">LangCode</td><td width="85%">The <a href="http://ahkscript.org/docs/misc/Languages.htm">language code</a>. <br>Please note that hexadecimal numbers must have an <code>0x</code> prefix.<br>The default resource language is US English (0x0409).<br>This directive is positional and affects all <code>AddResource</code> directives that follow it.<br></td></tr>
</table>
</div>

</body>
</html>
